package jzc.mzxy.datebinding;

import android.content.Intent;
import android.content.SharedPreferences;
import android.databinding.BindingAdapter;
import android.databinding.DataBindingUtil;
import android.databinding.ObservableField;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import java.util.HashMap;
import java.util.Map;

import jzc.mzxy.datebinding.BR;
import jzc.mzxy.datebinding.databinding.ActivityLoginBinding;
import jzc.mzxy.datebinding.databinding.ActivityMainBinding;
import jzc.mzxy.datebinding.moder.BannerModer;
import jzc.mzxy.datebinding.moder.LoginModer;
import jzc.mzxy.datebinding.moder.Login_Moder;
import retrofit2.Call;
import retrofit2.Callback;

public class loginActivity extends AppCompatActivity {
    ObservableField<String> username=new ObservableField<>();
    ObservableField<String> password=new ObservableField<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityLoginBinding binding= DataBindingUtil.setContentView(this,R.layout.activity_login);
        username.set("c1732");
        password.set("123456");
        binding.setVariable(BR.u,username);
        binding.setVariable(BR.p,password);
//        final LoginModer loginModer=new LoginModer();
//        loginModer.setUsername("jzc");
//        loginModer.setPassword("123456");
//        binding.setVariable(BR.login,loginModer);
        binding.setVariable(BR.click,new Myclick());
//        findViewById(R.id.loginbtn).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                loginModer.setUsername("pdd");
//                loginModer.setPassword("12345657");
//            }
//        });
//
        }

    public class Myclick{
        public void myclick1(Login_Moder login_Moder){
            Call<Login_Moder> login_ModerCall =RetrofitUtils.getRetrofit().create(Apis.class).getLogin(username.get(),password.get());;
            login_ModerCall.enqueue(new Callback<Login_Moder>() {
                @Override
                public void onResponse(Call<Login_Moder> call, retrofit2.Response<Login_Moder> response) {
                    Login_Moder login_Moder=response.body();
                }

                @Override
                public void onFailure(Call<Login_Moder> call, Throwable throwable) {

                }
            });
//
//            RequestQueue queue= Volley.newRequestQueue(loginActivity.this);
//            StringRequest request=new StringRequest(Request.Method.POST, "http://148.70.46.9:8080/boxuegu/bxg/login", new Response.Listener<String>() {
//                @Override
//                public void onResponse(String response) {
//                    Log.i("queue","response"+response);
//                }
//            },new Response.ErrorListener() {
//                @Override
//                public void onErrorResponse(VolleyError error) {
//
//
//                }})
//            {
//                @Override
//                protected Map<String, String> getParams() throws AuthFailureError {
//                    Map<String,String> map=new HashMap<>();
//                    map.put("username","c1732");
//                    map.put("password","123456");
//                    return map;
//                }
//            };
//            queue.add(request);
//            loginModer.setUsername("456");
//            loginModer.setPassword("45646");
//            Log.i("Myclick","myclick1" + loginModer);

        }
    }
}
